package edu.uaskl.jqf.model.gates;

import java.util.List;
import static edu.uaskl.jqf.tools.MathTools.ONE_OVER_SQRT_2;

import edu.uaskl.jqf.model.Complex;
import edu.uaskl.jqf.model.gates.util.BaseGate;
import edu.uaskl.jqf.model.matrix.MatrixComplex;

public class InverseQuantumFourierTransformation extends BaseGate {
    public static final MatrixComplex size2 = new MatrixComplex(new double[][] { { ONE_OVER_SQRT_2, ONE_OVER_SQRT_2 }, { ONE_OVER_SQRT_2, -ONE_OVER_SQRT_2 } });

    @Override
    public MatrixComplex getInstance() {
        return size2;
    }

    @Override
    public MatrixComplex getSize(final int size) {
        final Complex[][] array = new Complex[size][size];
        final double factor = 1.0 / Math.sqrt(size);
        final List<Complex> nthRootsOfUnity = Complex.getNthRootsOfUnity(size);
        for (int j = 0; j < array.length; j++)
            for (int i = 0; i < array.length; i++)
                array[j][i] = nthRootsOfUnity.get((i * j) % size).multiply(factor);
        return MatrixComplex.createMatrixBasedOnArray2d(array);
    }

}
